<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Hello World</title>
  <script src="https://unpkg.com/vue"></script>

</head>

<body>
  <div id="root"></div>
  <script>
    /* 
      1. v-once 只渲染一次，数据改变后不再改变
      2. ref
        - 声明 ref
        - 获取 this.$refs
          - 组件 获取组件实例
          - 非组件 获取DOM元素
      3. provide/inject
      - 源组件提供数据，目标组件注入数据
      - 源组件修改数据，目标组件不会改变，一次性绑定，非数据绑定
    */
    const child = {
      inject: ['msg'],
      template: `<div>
          child - <span ref="title"> {{msg}}</span>
      </div>`,
      mounted() {
        console.log(this.$refs.title)
      },
    }
    const son = {
      template: `<div>
        <child />
      </div>`,
      components: { child }
    }
    const app = Vue.createApp({
      data() {
        return {
          count: 0
        }
      },
      components: { son },
      provide: {
        msg: 'hello world'
      },
      template: `<div>
        <son ref="sonRef"/>
      </div>`,
      mounted() {
        console.log(this.$refs.sonRef)
      },
    })
    const vm = app.mount('#root');
  </script>
</body>

</html>